package com.ruoyi.xh.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TablePageDataInfo;
import com.ruoyi.common.core.domain.CommentResult;
import com.ruoyi.xh.domain.XhCar;
import com.ruoyi.xh.service.IXhCarService;

/**
 * 用户购物车Controller
 *
 * @author songjw
 * @date 2024-12-13
 */
@Api(tags = "用户购物车Controller",value = "用户购物车Controller")
@RestController
@RequestMapping("/xh/car")
public class XhCarController extends BaseController {

    @Autowired
    private IXhCarService xhCarService;

    /**
     * 查询用户购物车列表
     */
    @PreAuthorize("@ss.hasPermi('xh:car:list')")
    @GetMapping("/list")
    @ApiOperation("查询用户购物车列表")
    public TablePageDataInfo<XhCar> list(XhCar xhCar) {
        return TablePageDataInfo.success(xhCarService.selectXhCarList(xhCar));
    }

    /**
     * 获取用户购物车详细信息
     */
    @PreAuthorize("@ss.hasPermi('xh:car:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取用户购物车详细信息")
    public CommentResult<XhCar> getInfo(@PathVariable("id") Long id) {
        return CommentResult.success(xhCarService.selectXhCarById(id));
    }

    /**
     * 新增用户购物车
     */
    @PreAuthorize("@ss.hasPermi('xh:car:add')")
    @Log(title = "用户购物车", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增用户购物车")
    public CommentResult<XhCar> add(@RequestBody XhCar xhCar) {
            xhCarService.insertXhCar(xhCar);
        return CommentResult.success();
    }

    /**
     * 修改用户购物车
     */
    @PreAuthorize("@ss.hasPermi('xh:car:edit')")
    @Log(title = "用户购物车", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改用户购物车")
    public CommentResult<XhCar> edit(@RequestBody XhCar xhCar) {
            xhCarService.updateXhCar(xhCar);
        return CommentResult.success();
    }

    /**
     * 删除用户购物车
     */
    @PreAuthorize("@ss.hasPermi('xh:car:remove')")
    @Log(title = "用户购物车", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除用户购物车")
    public CommentResult<XhCar> remove(@PathVariable Long[] ids) {
            xhCarService.deleteXhCarByIds(ids);
        return CommentResult.success();
    }
}
